package com.zggk.framework.controller.score;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.platform.framework.controller.BaseController;
import com.zggk.framework.entity.score.GjContentcomm;
import com.zggk.framework.entity.score.GjContenthigh;
import com.zggk.framework.service.score.GjContentcommService;
import com.zggk.framework.service.score.GjContenthighService;

/**
 * @Description 评分标准控制层
 * @author 张立增
 * @Date 2020年2月27日 上午11:17:13
 */

@RestController
@RequestMapping("/scoringCriteria")
public class ScoringCriteriaController extends BaseController {

	
	@Autowired
	GjContentcommService gjContentcommService;

    @Autowired
    GjContenthighService gjContenthighService;
	
	/**
	* @Description 跳转到评分标准主页面的方法
	* @author 张立增[zhanglizeng] Tel：18860126570
	* @createDate 2020-02-26 11:30:46
	*/
    @RequestMapping(value = "/index")
	public ModelAndView index() {
		ModelAndView mv = new ModelAndView("score/scoringCriteria/index");
		return mv;
	}
    
    /**
	* @Description 跳转到评分标准新增页面的方法
	* @author 张立增[zhanglizeng] Tel：18860126570
	* @createDate 2020-02-26 11:30:46
	*/
    @RequestMapping(value = "/edit")
	public ModelAndView edit() {
		ModelAndView mv = new ModelAndView("score/scoringCriteria/edit");
		return mv;
	}
    
    /**
     * @Description 通过路线类型得到父编号
     * @author 张立增
     * @Date 2020年2月27日 下午2:38:56
     */
    @RequestMapping(value="/getPidTreeByRoadType",method= {RequestMethod.POST,RequestMethod.GET})
	public String getPidTreeByRoadType(HttpServletRequest request) throws Exception{
		String roadType = request.getParameter("roadType"); 
		if("H".equals(roadType)) {    //高速
			return gjContenthighService.getPidTree();
		}else {//普通
			return gjContentcommService.getPidTree();
		}
	}
   
    /**
     * @Description 检查id是否存在的方法
     * @author 张立增
     * @Date 2020年2月27日 下午4:42:37
     */
    @RequestMapping(value="/checkIdExist",method= {RequestMethod.POST,RequestMethod.GET})
   	public String checkIdExist(HttpServletRequest request) throws Exception{
   		String roadType = request.getParameter("roadType"); 
   		String id = request.getParameter("id"); 
   		if("H".equals(roadType)) {    //高速
   			return gjContenthighService.checkIdExist(id);
   		}else {//普通
   			return gjContentcommService.checkIdExist(id);
   		}
   	}
    
    /**
     * @Description 添加数据
     * @author 张立增
     * @Date 2020年2月28日 下午12:38:33
     */
    @RequestMapping(value = "dataAdd", method = { RequestMethod.POST })
	public String dataAdd(HttpServletRequest request){
		String data = request.getParameter("data");
		GjContenthigh gjContenthigh =  JSONObject.parseObject(data, GjContenthigh.class);
		if("H".equals(gjContenthigh.getRoadType())) {    //高速
   			return gjContenthighService.dataAdd(gjContenthigh);
   		}else {//普通
   			GjContentcomm gjContentcomm =  JSONObject.parseObject(data, GjContentcomm.class);
   			return gjContentcommService.dataAdd(gjContentcomm);
   		}
	}
    
    /**
     * @Description 更新数据
     * @author 张立增
     * @Date 2020年2月28日 下午12:38:33
     */
    @RequestMapping(value = "dataUpdate", method = { RequestMethod.POST })
	public String dataUpdate(HttpServletRequest request){
		String data = request.getParameter("data");
		GjContenthigh gjContenthigh = JSONObject.parseObject(data, GjContenthigh.class);
		if("H".equals(gjContenthigh.getRoadType())) {    //高速
   			return gjContenthighService.dataUpdate(gjContenthigh);
   		}else {//普通
   			GjContentcomm gjContentcomm = JSONObject.parseObject(data, GjContentcomm.class);
   			return gjContentcommService.dataUpdate(gjContentcomm);
   		}
	}
    
    /**
     * @Description 删除记录
     * @author 张立增
     * @Date 2020年2月28日 下午8:04:22
     */
    @RequestMapping(value = "delete", method = { RequestMethod.POST,RequestMethod.GET })
	public String delete(HttpServletRequest request){
		String ids = request.getParameter("ids");
		String roadType = request.getParameter("roadType");
		if("H".equals(roadType)) {    //高速
   			return gjContenthighService.deleteByIds(ids);
   		}else {//普通
   			return gjContentcommService.deleteByIds(ids);
   		}
	}
    
    
    
    
    
    
    
    
    
	
}
